
import React, { useEffect, useState } from 'react';
import Head from 'next/head';
import { StoreProvider, useStore } from '@/store';
import { Login } from '@/components/Login';
import '../styles/global.scss';
import { Layout} from '../components/Layout'
import { setPv_new } from '@/utils';
import { observer } from 'mobx-react-lite';
import { refreshRem } from './h5/rem';

function App(props: { Component: any; pageProps: any;isH5:boolean }) { 
    const { Component, pageProps } = props
    const store = useStore()
    useEffect(() => { 
        setPv_new(7607)
    }, [])
    
    useEffect(() => { 
        store.user?.setIsH5 && store.user.setIsH5(props.isH5)
    }, [store.user?.isH5])
    
    return (
        <StoreProvider initialValue={{ user: {id:0,username:'',avatar:''} }}>
            <>
                { props.isH5?null:<Login></Login>}
                <Head>
                    <title>怪兽AI-AI绘图助你释放创造力</title>
                    <meta name="description" content="零基础，轻松绘画！尽情探索AI绘画的无限可能！" />
                    { props.isH5?
                    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no,viewport-fit=cover" />:
                    <script id="CaptchaScript" src="//js.tuguaishou.com/ips_ai_home_static/captcha.js" defer></script>}
                </Head>
                <Component pageProps={...pageProps}></Component>
            </>
        </StoreProvider>
    )
}

App.getInitialProps = async (ctx: { router: { asPath: string; }; }) => {
    const isH5 = (ctx.router.asPath as string).includes('/h5')
     return { isH5 }
}

export default observer(App)